﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using FunctionalCLR.Core.Logging;

namespace Zove.Desktop {
    public partial class MessageForm : Form {

        public static MessageForm Instance {
            get;
            set;
        }

        public MessageTabPageCollection Pages {
            get;
            set;
        }

        public MessageForm() {
            InitializeComponent();

            Pages = new MessageTabPageCollection(this.tabControl1.TabPages);
            this.FormClosed += new FormClosedEventHandler(MessageForm_FormClosed);
        }

        public void MessageForm_FormClosed(object sender, EventArgs e) {
            Instance = null;
        }

        public void ShowInsideMdiParent() {
            this.MdiParent = this.MdiParent;
            this.Dock = DockStyle.Bottom;
            this.Show();
        }

        public void ShowMessages(
            string tabName, List<LoggingMessage> messages) {
            TabPage page = this.Pages[tabName];

            MessageGridView messageGridView 
                = (MessageGridView)page.Controls["MessageGridView"];
            messageGridView.Messages = messages;
            messageGridView.BindMessages();

            this.ShowInsideMdiParent();
        }
    }
}
